<?php
class Previllege
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    /**
     * @var string
     */
   
    public function __construct()
    {
		$this->_db = Zend_Registry::get('db');
    }
   
    public function listControllers()
    {
        $sql=" select * from aml_controllers where name<> 'previllege' " ;
        return $this->_db->fetchAll($sql);

    }
        public function getprevilleges()
    {
        $sql=" select * from aml_acl a right join aml_controllers b on a.component=b.name and b.name<>'previllege' and a.role<>'admin' ";
        return $this->_db->fetchAll($sql);

    }

       public function saveprevilleges($arr)
    {
        $this->_db->exec(" delete from    aml_acl   where role not in ('admin') and component not in ('previllege') ");
        
        foreach($arr["previllegeassign"] as $key=>$val){
            $valarr=explode("-",$key);

                  $this->_db->exec("insert into aml_acl (role,component,action,type) values ('{$valarr[1]}','{$valarr[0]}','{$valarr[2]}',1) ");
             if($valarr[2]=="add")
             {
                 $this->_db->exec("insert into aml_acl (role,component,action,type) values ('{$valarr[1]}','{$valarr[0]}','doadd',1) ");
             }
            elseif ($valarr[2]=="edit") {
                  $this->_db->exec("insert into aml_acl (role,component,action,type) values ('{$valarr[1]}','{$valarr[0]}','doedit',1) ");
             }
        }


    }
  

      public function checkprevrececord($arr)
    {
          $valarr= $arr;
        $sql=" select * from aml_acl where role='{$valarr[1]}' and component='{$valarr[0]}' and action='{$valarr[2]}' ";
        $exist= $this->_db->fetchAll($sql);
        if($exist)
        {
            return true;
        }
        else{
            return false;
        }
       
    }


}